<template>
  <nav class="category_bar">
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div
          class="swiper-slide"
          v-for="(item, index) in categoryItems"
          :key="index"
        >
          <li v-for="(subItem, i) in item" :key="i">
            <!-- <img :src="imageUrl + subItem.image_url" alt="" /> -->
            <!-- 测试图片 -->
            <img src="@/assets/images/9.png" alt="" />
            <span>{{ subItem.title }}</span>
          </li>
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>
    </div>
  </nav>
</template>

<script>
import Swiper from 'swiper/js/swiper';
import 'swiper/css/swiper.css';

import { imageUrl } from '@/config/env';

export default {
  props: {
    categoryItems: {
      type: Array,
      default: function() {
        return [];
      }
    }
  },
  data() {
    return {
      swiper: null,
      imageUrl
    };
  },
  watch: {
    categoryItems() {
      this.$nextTick(() => {
        this.swiper = new Swiper('.swiper-container', {
          loop: true,
          pagination: {
            el: '.swiper-pagination'
          }
        });
      });
    }
  }
};
</script>

<style lang="less" scoped>
.category_bar {
  border-radius: 6px;
  background-color: #fff;
}
.swiper-slide {
  display: flex;
  flex-wrap: wrap;
  padding-bottom: 20px;
  li {
    flex: 25%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 10px 0;
    img {
      width: 44px;
      height: 44px;
    }
    span {
      margin-top: 10px;
      font-size: var(--font-size);
    }
  }
}
</style>
